<?php
include 'include.php';

if(!isLoggedIn())
    header("Location:home.php");
    $menu = menu();
    $use = $db->get_row("Select * from Users where id='".$_SESSION['id']."'");

    //if(isAdminLoggedIn())
    //{
        $colors = array('White', 'MediumSpringGreen', 'LightSalmon', 'DarkOrange', 'Red');
        $page = "";

        $date1 = date('Y-m-d', strtotime("-5 days")); //date('Y-m-d');
        $date2 = date('Y-m-d', strtotime("+5 days"));
        $reminders = $db->get_results("Select * from Reminder WHERE date between '$date1'AND '$date2' and priority>'3';");
        if($reminders != null)
        {
            $page .= '<table id="rounded-corner" summary="">
            <thead>
                <tr>
                    <th scope="col" class="rounded-company">Date</th>
                    <th scope="col" class="rounded">Contact Comment</th>
                    <th scope="col" class="rounded">Contact Status</th>
                    <th scope="col" class="rounded">Reminder for</th>
                    <th scope="col" class="rounded">Related Donor</th>

                </tr>
            </thead>';
            foreach ($reminders as $rem) { //$num++;
                if($rem->type == 1)
                    $donor = $db->get_row("Select * from donors where id=".$rem->typeId);
                else if($rem->type == 2)
                {
                    $donn =  $db->get_var("Select donorId from donations where id=".$rem->typeId);
                    $donor = $db->get_row("Select * from donors where id=".$donn);
                }
                else if($rem->type == 3)
                {
                    $donn =  $db->get_var("Select donorId from communications where id=".$rem->typeId);
                    $donor = $db->get_row("Select * from donors where id=".$donn);
                }
                $page .= "<tr style='background-color:".$colors[$rem->priority-1]."; color:black'>
                <td style='background-color:".$colors[$rem->priority-1]."; color:black'> $rem->date </td>
                <td style='background-color:".$colors[$rem->priority-1]."; color:black'> $rem->comment </td>
                <td style='background-color:".$colors[$rem->priority-1]."; color:black'> ".getReminderStatusName($rem->status)."</td>

                <td style='background-color:".$colors[$rem->priority-1]."; color:black'> ".getReminderName($rem->type) ."</td>
                    <td style='background-color:".$colors[$rem->priority-1]."; color:black'><a href='donor.php?page=item&id=".$donor->id."'> $donor->name </td>
                </tr>";
            }
            $page .= "</tbody></table>";
        }
    //}
    //else
    //{
        //$page = "Display info.";
    //}
    $template = new template("Dashboard");
    $template->showMenu($menu);
    $template->showLogin("Welcome");
    $template->showUser($use->name.' | <a href="logout.php" class="logout">Logout</a>');
    //$template->showMsg($num);
    $template->addContent($page);
    $template->genPage();
?>
